<style lang="less" scoped>
    @import '../../styles/common.less';
    .main-table {
        margin-top: 10px;
    }
    .pagination {
        margin-top: 10px;
        padding: 0 10px;
    }
    .conts {
        margin-left: 0px;
        padding-top: 4px;
        text-align: center;
        font-weight: bold;
        font-size: 14px;
        border-bottom: 1px #c5d0dc solid;
    }
</style>

<template>
    <div>
        <Row>
            <span @click="showAdd"><Button type="primary" icon="android-add">新增</Button></span>
        </Row>
        <div class="main-table">
            <Table border :columns="columns" :data="data"></Table>
        </div>
        <div class="pagination">
            <Page :total="total" size="small" :page-size="pageSize" :current.sync="pageIndex" @on-change="loadList" show-total show-elevator></Page>
        </div>
        <Modal
                v-model="modalVisible"
                title="积分信息"
                @on-ok="modalVisible = false"
                @on-cancel="modalVisible = false"
                width="90%">
             <Form :model="formData" :label-width="80">
                <FormItem label="ID">
                    {{formData.id}}
                </FormItem>
                <FormItem label="积分">
                    {{formData.integral}}
                </FormItem>
              
             
                <FormItem label="状态">
                    {{formData.state}}
                </FormItem>
            </Form>
        </Modal>
        <Modal v-model="saveModalVisible" :title="(formData.id ? '修改' : '新增') + '用户'" width="85%">
            <Form :model="formData" :label-width="125">
                <Row>
                    <Col span="8">
                    <FormItem label="积分">
                        <Input v-model="formData.integral" clearable ></Input>
                    </FormItem>
                    </Col>
					<Col span="8">
                    <FormItem label="状态">
                        <Input v-model="formData.state" clearable ></Input>
                    </FormItem>
                    </Col>
                  
                    <Col span="8">
                    </Col>
                </Row>              
            </Form>
            <div slot="footer">
                <Button type="primary" @click="userSave">保存</Button>
                <Button type="ghost" style="margin-left: 8px" @click="saveModalVisible = false">取消</Button>
            </div>
        </Modal>
    </div>
</template>

<script>
    import util from '@/libs/util';

    const formStructure = {
   
   
        integral: '',
        state: '',
        id: ''
    };

    export default {
        name: 'exportable-table',
        data () {
            return {
                columns: [{
                    title: '序号',
                    key: 'number',
                    width: 50,
                    align: 'center'
                }, {
                    title: '积分',
                    key: 'integral'
                },{title:'状态',
				   key:'state'},
				   {
                    title: '操作',
                    key: 'action',
                    width: 200,
                    align: 'center',
                    render: (h, params) => {
                        return h('div', [
                            h('Button', {
                                props: {
                                    type: 'primary',
                                    size: 'small'
                                },
                                style: {
                                    marginRight: '5px'
                                },
                                on: {
                                    click: () => {
                                        this.detail(params.row.id);
                                    }
                                }
                            }, '详情'),
                            h('Button', {
                                props: {
                                    type: 'primary',
                                    size: 'small'
                                },
                                style: {
                                    marginRight: '5px'
                                },
                                on: {
                                    click: () => {
                                        this.showEdit(params.row);
                                    }
                                }
                            }, '修改'),
                            h('Button', {
                                props: {
                                    type: 'error',
                                    size: 'small'
                                },
                                on: {
                                    click: () => {
                                        this.delete(params.row.id)
                                    }
                                }
                            }, '删除')
                        ]);
                    }
                }],
                data: [],
                formData: {isIdCard:'NO'},
                modalVisible: false,
                saveModalVisible: false,

                total: 0,
                pageIndex: 1,
                pageSize: 10,
               
             
                typeList:[],
                stateList:[{
                    value: 'APPLYING',
                    label: '正在报名'
                },{
                    value: 'END',
                    label: '结束'
                }],
                vehicleList:[],
                isRelease:[{
                    value: 'YES',
                    label: '是'
                },{
                    value: 'NO',
                    label: '否'
                }],
                timeList:[]
            };
        },
        mounted() {
            this.loadList();
        },
        methods: {
            loadList() {
                util.ajax.post('base/integral/list', util.toFormData({
                    page: this.pageIndex,
                    size: this.pageSize,
                })).then(res => {
				
                    var lists =  res.data.data.list;
					
             
                    this.data = lists;
					
                    this.total = res.data.data.total;
                
                   
                });
            },
            detail(id) {
                util.ajax.post('base/integral/detail', util.toFormData({
                    id: id
                })).then(res => {
                    if (res.data.data) {
                      this.formData = res.data.data;
					  this.modalVisible = true;
                    } else {
                        this.$Modal.error({
                            title: '警告',
                            content: '出错了'
                        });
                    }
                });
            },
            showAdd() {
                this.formData = {isIdCard:'NO'};
                this.saveModalVisible = true;
            },
            showEdit(obj) {
			
                this.formData = {};
                for (let key in formStructure) {
                    this.formData[key] = obj[key];
					
                }
                this.saveModalVisible = true;
            },
            userSave(){
                let formData = {};
                for (let key in this.formData) {
                    formData[key] = this.formData[key];
                }
                util.ajax.post('base/integral/save', util.toFormData(formData)).then(res => {
                    if (res.data.message === 'SUCCESS') {
                        this.saveModalVisible = false;
                        this.$Message.success('保存成功！');
                        this.pageIndex = 1;
                        this.loadList();
                    } else {
                        this.$Message.warning(res.data.message || '未知错误！');
                    }
                });
            },
            delete(id) {
                this.$Modal.confirm({
                    title: '提示',
                    content: '<p>确定删除？</p>',
                    onOk: () => {
                        util.ajax.post('base/integral/delete', util.toFormData({
                            id: id
                        })).then(res =>{
                            if(res.data.message === 'SUCCESS'){
                                this.$Message.success('删除成功！');
                                this.loadList();
                            }
                        });
                    },
                    onCancel: () => {
                    }
                });
            },
            getDate(data){
                let myDate;

                if(data){
                    myDate = new Date(data);
                }else{
                    myDate = new Date();
                }

                let Y = myDate.getFullYear(),
                    M = myDate.getMonth() + 1,
                    D = myDate.getDate() + 1,
                    H = myDate.getHours(),
                    Min = myDate.getMinutes(),
                    S = myDate.getSeconds();

                if(M < 10){
                    M = '0' + M ;
                }
                if(D < 10){
                    D = '0' + D ;
                }
                if(H < 10){
                    H = '0' + H ;
                }
                if(Min < 10){
                    Min = '0' + Min ;
                }
                if(S < 10){
                    S = '0' + S ;
                }
                return Y + '-' + M + '-' + D;
            },
            addTime(){
                this.timeList++
            },
            delTime(){
                this.timeList--
            }
        }
    };
</script>
